﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InformationSystem.BLL.Core.Model;
using InformationSystem.BLL.Core.Service;
using System.IO;

namespace InformationSystem.WebSite.Module.DocumentMgr
{
    public partial class Documentdownload : BasePage
    {
        public ISharedDocumentService SharedDocumentService;
        LoginUser user = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            user = (LoginUser)Session["LoginUser"];
            int id = 0;
            if (Request.QueryString["id"] == null) return;
            if (!int.TryParse(Request.QueryString["id"], out id)) return;
            FileInformation file = SharedDocumentService.GetDocumentDetailByID(id);
            if (file == null)
                return;
            string path = Path.Combine(Server.MapPath("~"), Common.DocumentPath, file.CollegeId.ToString(), file.GradeId.ToString(), file.SaveFileName);
            if (File.Exists(path))
            {
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                String httpHeader = "attachment;filename=" + HttpUtility.UrlEncode(file.UploadFileName);
                this.Response.Clear();
                this.Response.AddHeader("Content-Disposition", httpHeader);
                this.Response.WriteFile(path);
                this.Response.End();
            }
        }

        protected override bool CommitPermissionCheck()
        {
            throw new NotImplementedException();
        }
    }
}